<template>
    <el-form ref="ruleFormRef" :model="ruleForm" label-width="auto" :rules="rules" :size="formSize" status-icon >
        <el-tabs :tab-position="tabPosition" style="height: 200px">
            <el-tab-pane label="基本信息">
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="姓名" prop="name">
                            <el-input v-model="ruleForm.name" />
                        </el-form-item>
                        <el-form-item label="证件类型" prop="id_type">
                            <el-radio-group v-model="ruleForm.id_type">
                                <el-radio :value="1" >身份证</el-radio>
                                <el-radio :value="2" >护照</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="民族" prop="ethnicity">
                            <el-select v-model="ruleForm.ethnicity" placeholder="请选择">
                                <el-option v-for="item in ethnicGroups" :key="item" :label="item" :value="item" />
                            </el-select>
                        </el-form-item>
                        <el-form-item label="手机号码" prop="mobile">
                            <el-input v-model="ruleForm.mobile" maxlength="11" show-word-limit />
                        </el-form-item>
                        <el-form-item label="邮箱" prop="email">
                            <el-mention v-model="ruleForm.more.email" :options="email_" />
                        </el-form-item>
                        <el-form-item label="政治面貌" prop="political_status">
                            <el-select v-model="ruleForm.political_status" placeholder="请选择">
                                <el-option label="中共党员" value="中共党员" />
                                <el-option label="无党派人士" value="无党派人士" />
                                <el-option label="群众" value="群众" />
                            </el-select>
                        </el-form-item>
                        <el-form-item label="文化程度" prop="education">
                            <el-select v-model="ruleForm.education" placeholder="请选择">
                                <el-option label="初中及以下" value="初中及以下" />
                                <el-option label="中专" value="中专" />
                                <el-option label="高中" value="高中" />
                                <el-option label="技校" value="技校" />
                                <el-option label="大学专科" value="大学专科" />
                                <el-option label="大学本科" value="大学本科" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="出生日期" prop="birth_date">
                            <el-date-picker style="width: 100%" v-model="ruleForm.birth_date" type="date" value-format="YYYY-MM-DD" placeholder="请选择日期" />
                        </el-form-item>
                        <el-form-item label="证件号码" prop="idcard">
                            <el-input v-model="ruleForm.idcard" />
                        </el-form-item>
                        <el-form-item label="性别" prop="sex">
                            <el-radio-group v-model="ruleForm.sex">
                                <el-radio :value="1" >男</el-radio>
                                <el-radio :value="0" >女</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="岗位" prop="posts">
                            <el-input v-model="ruleForm.posts" />
                        </el-form-item>
                        <el-form-item label="在职/离职" prop="employees">
                            <el-radio-group v-model="ruleForm.employees">
                                <el-radio :value="1" >在职</el-radio>
                                <el-radio :value="2" >离职</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="编内/编外" prop="formal">
                            <el-radio-group v-model="ruleForm.formal">
                                <el-radio :value="1" >编内</el-radio>
                                <el-radio :value="0" >编外</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="密码" prop="password">
                            <el-input v-model="ruleForm.password" placeholder="不填则不作修改" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8"><div class="text-center"><el-image style="width: 200px; height: 200px" @click="onUploadFile('avatar')" :src="ruleForm.avatar" /></div></el-col>
                </el-row>
                <el-form-item label="户籍所在地" prop="household_register">
                    <el-input style="width: 600px" v-model="ruleForm.household_register"  />
                </el-form-item>
                <el-form-item label="居住地址" prop="residential_address">
                    <el-input style="width: 600px" v-model="ruleForm.residential_address"  />
                </el-form-item>
                <el-form-item label="合同" >
                    <el-radio-group v-model="ruleForm.contract_type">
                        <el-radio value="劳动合同" >劳动合同</el-radio>
                        <el-radio value="劳务合同" >劳务合同</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="劳动/劳务合同" >
                    <el-row >
                        <el-col :span="4">
                            <el-date-picker style="width: 100%" v-model="ruleForm.contract_start_date" type="date" value-format="YYYY-MM-DD" placeholder="请选择日期" />
                        </el-col>
                        <el-col :span="1">
                             <div class="text-center">至</div>
                        </el-col>
                        <el-col :span="4">
                            <el-date-picker style="width: 100%" v-model="ruleForm.contract_end_date" type="date" value-format="YYYY-MM-DD" placeholder="请选择日期" />
                        </el-col>
                        <el-col :span="2">
                             <div class="text-right">试用期: </div>
                        </el-col>
                        <el-col :span="4">
                             <el-date-picker style="width: 100%" v-model="ruleForm.trial_start_period" type="date" value-format="YYYY-MM-DD" placeholder="请选择日期" />
                        </el-col>
                        <el-col :span="1">
                             <div class="text-center">至</div>
                        </el-col>
                        <el-col :span="4">
                            <el-date-picker style="width: 100%" v-model="ruleForm.trial_end_period" type="date" value-format="YYYY-MM-DD" placeholder="请选择日期" />
                        </el-col>
                    </el-row>
                </el-form-item>
                <el-form-item label="身份证复印件" prop="idcard_file">
                    <el-button type="primary"  @click="onUploadFile('idcard_file')"> 上传 </el-button>
                    <el-button :type="ruleForm.more.idcard_file ? 'primary' : 'info'"  @click="onShowFile(ruleForm.more.idcard_file)"> 查看 </el-button>
                </el-form-item>
            </el-tab-pane>
            <el-tab-pane label="学历信息">
                <el-button type="primary"  @click="insertEdu"> 添加 </el-button>
                <el-table class="mt20" :data="edus" style="width: 100%;height: 260px !important;">
                    <el-table-column prop="school" label="毕业院校"  />
                    <el-table-column prop="type" label="学习形式" width="110" />
                    <el-table-column prop="edu" label="学历" width="120" />
                    <el-table-column prop="major" label="专业" />
                    <el-table-column prop="in_date" label="入学时间" width="140" />
                    <el-table-column prop="graduate_date" label="毕业时间" width="140" />
                    <el-table-column prop="system" label="学制" width="100" />
                    <el-table-column prop="numbers" label="学历证书编号" width="200" />
                    <el-table-column prop="degree_numbers" label="学位证书编号"  width="200" />
                    <el-table-column label="检看" width="50">
                        <template #default="scope">
                            <el-text type="primary" @click="onShowFile(scope.row.cert)" >检看</el-text>
                        </template>
                    </el-table-column>
                    <el-table-column fixed="right" label="操作" width="90">
                        <template #default="scope">
                            <el-link type="primary" @click="editEdu(scope.row.id)" >编辑</el-link>
                            <el-popconfirm title="确定要删除么?" @confirm="onEduDelete(scope.row.id)">
                                <template #reference>
                                    <el-link type="danger" >删除</el-link>
                                </template>
                            </el-popconfirm>
                        </template>
                    </el-table-column>
                </el-table>
            </el-tab-pane>
            <el-tab-pane label="专业技术资格">
                <el-button type="primary"  @click="insertCert(0,3)"> 添加 </el-button>
                <h4 class="mt10" >职称</h4>
                <el-table :data="certTitles" style="width: 100%;height: 200px !important;">
                    <el-table-column prop="title" label="证书类别" width="200" />
                    <el-table-column prop="level" label="资格等级" width="100" />
                    <el-table-column prop="major" label="专业" width="140"  />
                    <el-table-column prop="numbers" label="资格证书编号"  />
                    <el-table-column prop="approving_unit" label="批准单位" />
                    <el-table-column prop="jury_name" label="评委会名称"  />
                    <el-table-column prop="acquired_at" label="资格取得时间" width="120" />
                    <el-table-column label="检看" width="50">
                        <template #default="scope">
                            <el-link type="primary"  @click="onShowFile(scope.row.files)">检看</el-link>
                        </template>
                    </el-table-column>
                    <el-table-column fixed="right" label="操作" width="90">
                        <template #default="scope">
                            <el-link type="primary" @click="editCert(scope.row.id,3)" >编辑</el-link>
                            <el-popconfirm title="确定要删除么?" @confirm="onCertDelete(scope.row.id)">
                                <template #reference>
                                    <el-link type="danger" >删除</el-link>
                                </template>
                            </el-popconfirm>
                        </template>
                    </el-table-column>
                </el-table>

                <el-button type="primary"  @click="insertCert(0,2)"> 添加 </el-button>
                <h4 class="mt10" >岗位证书</h4>
                <el-table :data="certs" style="width: 100%;height: 200px !important;">
                    <el-table-column prop="title" label="证书类别"  width="200" />
                    <el-table-column prop="level" label="资格等级" width="100"   />
                    <el-table-column prop="major" label="专业" width="140" />
                    <el-table-column prop="numbers" label="资格证书编号"  />
                    <el-table-column prop="approving_unit" label="批准单位" />
                    <el-table-column prop="acquired_at" label="资格取得时间" width="120" />
                    <el-table-column prop="end_date" label="有效使用时间" />
                    <el-table-column label="检看" width="50">
                        <template #default="scope">
                            <el-link link type="primary"  @click="onShowFile(scope.row.files)">检看</el-link>
                        </template>
                    </el-table-column>
                    <el-table-column fixed="right" label="操作" width="90">
                        <template #default="scope">
                            <el-link link type="primary" @click="editCert(scope.row.id,2)" >编辑</el-link>
                            <el-popconfirm title="确定要删除么?" @confirm="onCertDelete(scope.row.id)">
                                <template #reference>
                                    <el-link link type="danger" >删除</el-link>
                                </template>
                            </el-popconfirm>
                        </template>
                    </el-table-column>
                </el-table>
            </el-tab-pane>
            <el-tab-pane label="薪资待遇">
                <el-row >
                    <el-col :span="8">
                        <el-form-item label="基本薪资" prop="basic_salary">
                            <el-input v-model="ruleForm.basic_salary" @change="onChangeUserSlary" />
                        </el-form-item>
                        <el-form-item label="研发奖励" prop="rewards">
                            <el-input v-model="ruleForm.more.rewards" @change="onChangeUserSlary" />
                        </el-form-item>
                        <el-form-item label="试用期工资" prop="probationary_salary">
                            <el-input v-model="ruleForm.more.probationary_salary" @change="onChangeUserSlary" />
                        </el-form-item>
                        <el-form-item label="开户行" prop="bank">
                            <el-input v-model="ruleForm.bank" />
                        </el-form-item>
                        <el-form-item label="银行行号" prop="bank_number">
                            <el-input v-model="ruleForm.bank_number" />
                        </el-form-item>
                        <el-form-item label="银行账号" prop="bank_account">
                            <el-input v-model="ruleForm.bank_account" />
                        </el-form-item>
                        <el-form-item label="薪资补充协议" prop="salary_agreements">
                            <el-button type="primary"  @click="onUploadFile('salary_agreements')"> 上传 </el-button>
                            <el-button :type="ruleForm.more.salary_agreements ? 'primary' : 'info'"  @click="onShowFile(ruleForm.more.salary_agreements)"> 查看 </el-button>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="岗位补贴" prop="subsidies">
                            <el-input v-model="ruleForm.more.subsidies" @change="onChangeUserSlary" />
                        </el-form-item>
                        <el-form-item label="其他补贴" prop="other_subsidies">
                            <el-input v-model="ruleForm.more.other_subsidies" @change="onChangeUserSlary" />
                        </el-form-item>
                        <el-form-item label="累计工资" prop="total_salary">
                            <el-text>{{ ruleForm.more.total_salary }}</el-text>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-tab-pane>
            <el-tab-pane label="入职信息">
                <el-row >
                    <el-col :span="8">
                        <el-form-item label="上家单位" prop="previous_unit">
                            <el-input v-model="ruleForm.more.previous_unit" type="textarea" :autosize="{ minRows: 4 }" />
                        </el-form-item>
                        <el-form-item label="电话" prop="previous_unit_mobile">
                            <el-input v-model="ruleForm.more.previous_unit_mobile" />
                        </el-form-item>
                        <el-form-item label="社保证明" prop="social_security_cert">
                            <el-button type="primary"  @click="onUploadFile('social_security_cert')"> 上传 </el-button>
                            <el-button :type="ruleForm.more.social_security_cert ? 'primary' : 'info'"  @click="onShowFile(ruleForm.more.social_security_cert)"> 查看 </el-button>
                        </el-form-item>
                        <el-form-item label="入职登记表" prop="employment_form">
                            <el-button type="primary"  @click="onUploadFile('employment_form')"> 上传 </el-button>
                            <el-button :type="ruleForm.more.employment_form ? 'primary' : 'info'"  @click="onShowFile(ruleForm.more.employment_form)"> 查看 </el-button>
                        </el-form-item>
                        <el-form-item label="员工手册" prop="company_policy_agreement">
                            <el-button type="primary"  @click="onUploadFile('company_policy_agreement')"> 上传 </el-button>
                            <el-button :type="ruleForm.more.company_policy_agreement ? 'primary' : 'info'"  @click="onShowFile(ruleForm.more.company_policy_agreement)"> 查看 </el-button>
                        </el-form-item>
                        <!-- <el-form-item label="员工手册、保密、培训协议" prop="company_policy_agreement">
                            <el-button type="primary"  @click="onUploadFile('company_policy_agreement')"> 查看 </el-button>
                        </el-form-item> -->
                        <el-form-item label="调岗、调薪申请" prop="employment_registration">
                            <el-button type="primary"  @click="onUploadFile('employment_registration')"> 上传 </el-button>
                            <el-button :type="ruleForm.more.employment_registration ? 'primary' : 'info'"  @click="onShowFile(ruleForm.more.employment_registration)"> 查看 </el-button>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="证明人" prop="subsidies">
                            <el-input v-model="ruleForm.more.previous_unit_user" />
                        </el-form-item>
                        <el-form-item label="离职证明" prop="resignation_cert">
                            <el-button type="primary"  @click="onUploadFile('resignation_cert')"> 上传 </el-button>
                            <el-button :type="ruleForm.more.resignation_cert ? 'primary' : 'info'"  @click="onShowFile(ruleForm.more.resignation_cert)"> 查看 </el-button>
                        </el-form-item>
                        <el-form-item label="银行流水" prop="bank_statement">
                            <el-button type="primary"  @click="onUploadFile('bank_statement')"> 上传 </el-button>
                            <el-button :type="ruleForm.more.bank_statement ? 'primary' : 'info'"  @click="onShowFile(ruleForm.more.bank_statement)"> 查看 </el-button>
                        </el-form-item>
                        <el-form-item label="劳动合同" prop="labor_contract">
                            <el-button type="primary"  @click="onUploadFile('labor_contract')"> 上传 </el-button>
                            <el-button :type="ruleForm.more.labor_contract ? 'primary' : 'info'"  @click="onShowFile(ruleForm.more.labor_contract)"> 查看 </el-button>
                        </el-form-item>
                        <el-form-item label="转正申请表" prop="probation_approval_form">
                            <el-button type="primary"  @click="onUploadFile('probation_approval_form')"> 上传 </el-button>
                            <el-button :type="ruleForm.more.probation_approval_form ? 'primary' : 'info'"  @click="onShowFile(ruleForm.more.probation_approval_form)"> 查看 </el-button>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-tab-pane>
            <el-tab-pane label="离职信息">
                <el-form-item label="离职原因" prop="reason_leaving">
                    <el-input v-model="ruleForm.more.reason_leaving" type="textarea" :autosize="{ minRows: 4 }" :rows="6" />
                </el-form-item>
                <el-form-item label="约谈内容" prop="resignation_interview">
                    <el-input v-model="ruleForm.resignation_interview" type="textarea" :autosize="{ minRows: 4 }" :rows="6" />
                </el-form-item>
                <el-row >
                    <el-col :span="8">
                        <el-form-item label="交接记录" prop="handover_records">
                            <el-button type="primary"  @click="onUploadFile('handover_records')"> 上传 </el-button>
                            <el-button :type="ruleForm.more.handover_records ? 'primary' : 'info'"  @click="onShowFile(ruleForm.more.handover_records)"> 查看 </el-button>
                        </el-form-item>
                        <el-form-item label="离职证明书" prop="resignation_report">
                            <el-button type="primary"  @click="onUploadFile('resignation_report')"> 上传 </el-button>
                            <el-button :type="ruleForm.more.resignation_report ? 'primary' : 'info'"  @click="onShowFile(ruleForm.more.resignation_report)"> 查看 </el-button>
                        </el-form-item>
                        <el-form-item label="薪资结清证明" prop="salary_settlement_cert">
                            <el-button type="primary"  @click="onUploadFile('salary_settlement_cert')"> 上传 </el-button>
                            <el-button :type="ruleForm.more.salary_settlement_cert ? 'primary' : 'info'"  @click="onShowFile(ruleForm.more.salary_settlement_cert)"> 查看 </el-button>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="离职报告" prop="out_report">
                            <el-button type="primary"  @click="onUploadFile('out_report')"> 上传 </el-button>
                            <el-button :type="ruleForm.more.out_report ? 'primary' : 'info'"  @click="onShowFile(ruleForm.more.out_report)"> 查看 </el-button>
                        </el-form-item>
                        <el-form-item label="约谈记要" prop="resignation_interview_file">
                            <el-button type="primary"  @click="onUploadFile('resignation_interview_file')"> 上传 </el-button>
                            <el-button :type="ruleForm.more.resignation_interview_file ? 'primary' : 'info'"  @click="onShowFile(ruleForm.more.resignation_interview_file)"> 查看 </el-button>
                        </el-form-item>
                        
                    </el-col>
                </el-row>
            </el-tab-pane>
            <el-tab-pane label="权限管理">
                <component :is="authForm" :user_id = id />
            </el-tab-pane>
        </el-tabs>
    </el-form>
    <div class="mt20 text-center">

        <el-popconfirm name="确定要添加这个人到系统么?" @confirm="onStatus">
            <template #reference>
                <el-button type="success" v-if="ruleForm.status == 0" :loading="loading"> 确认通过 </el-button>
            </template>
        </el-popconfirm>
        <el-button type="primary" @click="submitForm(ruleFormRef)" :loading="loading"> 保存 </el-button>
        <el-button type="info" @click="router.go(-1)"> 返回 </el-button>
    </div>

    <el-dialog v-model="isCert" title="绑定证书" width="60%" draggable>
        <component :is="certForm" :user_id = userId :type="certType" :id="editId" @onSave="onSave" />
    </el-dialog>

    <el-dialog v-model="isEdu" title="人员学历" width="60%" draggable>
        <component :is="eduForm" :user_id = userId :type="0" :id="editId" @onSaveEdu="onSaveEdu" />
    </el-dialog>

    <el-dialog v-model="showUpload" title="文件" draggable>
        <component :is="uploadFile" :data="uploadData" @saveUpload="saveUpload" />
    </el-dialog>

    <el-dialog v-model="isShowFile" title="文件" class="m0" width="80%" @close="onCloseFile" draggable>
        <component :is="showFile" :data="files"/>
    </el-dialog>
</template>
  
<script lang="ts" setup>
import { onMounted,reactive,ref } from 'vue'
import { ElMessage, TabsInstance, type ComponentSize, type FormInstance,type FormRules } from 'element-plus'

import http from '../../../util/request';
// import upload from '@/components/upload.vue'
import uploadFile from '@/components/uploadFile.vue'
import showFile from '@/components/showFile.vue'
import certForm from "./components/certForm.vue";
import authForm from "./components/authForm.vue";
import eduForm from "./components/eduForm.vue";
import { useRouter } from 'vue-router';
import func from '../../../util/function';
import router from '../../../router';
const tabPosition = ref<TabsInstance['tabPosition']>('left')
const id:any = ref(useRouter().currentRoute.value.params.id)
const showUpload = ref<boolean>(false)
let uploadData:any = ref({prefix:'user/',type:''})
const ethnicGroups:string[] = func.ethnicGroups()

const loading = ref<boolean>(false)
const isEdu = ref<boolean>(false)
const isCert = ref<boolean>(false)
const userId = ref(0)
const editId = ref(0)
const certType = ref(0)
const files = ref('')
const isShowFile = ref<boolean>(false)
const certTitles = ref<any>([])
const certs = ref<any>([])
const edus = ref<any>([])


const formSize = ref<ComponentSize>('large')
const ruleFormRef = ref<FormInstance>()
const ruleForm = ref<any>({id:0,more:{email:'/'}})
const email_ = ref([
    {label: 'qq.com',value: 'qq.com',},
    {label: '163.com',value: '163.com',},
    {label: '126.com',value: '126.com',},
    {label: 'sina.com',value: 'sina.com',},
    {label: 'gmail.com',value: 'gmail.com',},
    {label: 'outlook.com',value: 'outlook.com',},
])

const onGetData = () => {
    if(id.value == 0){
        return
    }
    certs.value = []
    certTitles.value = []
    http.get('/user/'+id.value).then((response:any)=>{
        if(!response.data.data.more){
            response.data.data.more = {}
        }
        ruleForm.value = response.data.data
        
        response.data.data.certs.forEach((e:any) => {
            if(e.type == 2){
                certs.value.push(e)
            }
            if(e.type == 3){
                certTitles.value.push(e)
            }
        });
        
        edus.value = response.data.data.edus
    })
}

const rules = reactive<FormRules>({
    name: [
        { required: true, message: '请输入姓名', trigger: 'blur' },
    ],
    mobile: [
        { required: true, message: '请输入手机号码', trigger: 'blur' },
    ],
    idcard: [
        { required: true, message: '请输入证件号码', trigger: 'blur' },
        { min: 18, max: 18, message: '范围在18个数字', trigger: 'blur' },
    ],
})

const submitForm = async (formEl: FormInstance | undefined) => {
    if (!formEl) return
    await formEl.validate((valid, fields) => {
        if (valid) {
            loading.value = true
            let request:any = null
            if(ruleForm.value.id > 0){
                request = http.patch('/user',ruleForm.value)
            }else{
                request = http.put('/user',ruleForm.value)
            }
            request.then((response:any)=>{
                loading.value = false
                if(response.data.code != 200){
                    ElMessage.error(response.data.msg);return
                }
                ElMessage.success(response.data.msg);
                id.value = response.data.data.id
                onGetData()
            })
        } else {
            console.log('error submit!', fields)
        }
    })
}

const onStatus = () => {
    http.patch('/user/status',{id:ruleForm.value.id,status:1}).then((response:any)=>{
        if(response.data.code != 200){
            ElMessage.error(response.data.msg);return;
        }
        ElMessage.success(response.data.msg);
        onGetData();
    })
}

const onShowFile = (file:string) => {
    if(!file){
        ElMessage.error('未上传文件');return
    }
    files.value = file
    isShowFile.value = true
}

const onCloseFile = () => {
    files.value = ''
}


const insertEdu = () => {
    if(ruleForm.value.id == 0){
        ElMessage.error('请先保存用户基本信息');return
    }
    userId.value = ruleForm.value.id
    editId.value = 0
    isEdu.value = true
}

const editEdu = (data:number) => {
    if(ruleForm.value.id == 0){
        ElMessage.error('请先选择用户');return
    }
    userId.value = ruleForm.value.id
    editId.value = data
    isEdu.value = true
}

const insertCert = (id:number,type:number) => {
    if(ruleForm.value.id == 0){
        ElMessage.error('请先保存用户基本信息');return
    }
    console.log(id)
    certType.value = type
    userId.value = ruleForm.value.id
    editId.value = 0
    isCert.value = true
}

const editCert = (data:number,type:number) => {
    if(ruleForm.value.id == 0){
        ElMessage.error('请先选择用户');return
    }
    userId.value = ruleForm.value.id
    editId.value = data
    certType.value = type
    isCert.value = true
}

const onEduDelete = (id:number) => {
    http.delete('/user/edu/'+id).then((response:any)=>{
        if(response.data.code != 200){
            ElMessage.error(response.data.msg);return;
        }
        ElMessage.success(response.data.msg);
        onGetData();
    })
}

const onCertDelete = (id:number) => {
    http.delete('/cert/'+id).then((response:any)=>{
        if(response.data.code != 200){
            ElMessage.error(response.data.msg);return;
        }
        ElMessage.success(response.data.msg);
        onGetData();
    })
}

const onSaveEdu = () => {
    isEdu.value = false
    onGetData()
}

const onSave = () => {
    isCert.value = false
    onGetData()
}

const onChangeUserSlary = () => {
    ruleForm.value.more.total_salary = parseInt(ruleForm.value.basic_salary) + parseInt(ruleForm.value.more.rewards) + parseInt(ruleForm.value.more.probationary_salary) + parseInt(ruleForm.value.more.subsidies) + parseInt(ruleForm.value.more.other_subsidies)
}


onMounted(()=>{
    onGetData()
})

const onUploadFile = (type:string) => {
    uploadData.value.type = type
    if(type == 'avatar'){
        uploadData.value.file = ruleForm.value.avatar
    }
    if(type == 'salary_agreements'){
        uploadData.value.file = ruleForm.value.more.salary_agreements
    }
    if(type == 'social_security_cert'){
        uploadData.value.file = ruleForm.value.more.social_security_cert
    }
    if(type == 'bank_statement'){
        uploadData.value.file = ruleForm.value.more.bank_statement
    }
    if(type == 'employment_form'){
        uploadData.value.file = ruleForm.value.more.employment_form
    }
    if(type == 'labor_contract'){
        uploadData.value.file = ruleForm.value.more.labor_contract
    }
    if(type == 'company_policy_agreement'){
        uploadData.value.file = ruleForm.value.more.company_policy_agreement
    }
    if(type == 'probation_approval_form'){
        uploadData.value.file = ruleForm.value.more.probation_approval_form
    }
    if(type == 'idcard_file'){
        uploadData.value.file = ruleForm.value.more.idcard_file
    }
    if(type == 'contract'){
        uploadData.value.file = ruleForm.value.more.contract
    }
    if(type == 'employment_registration'){
        uploadData.value.file = ruleForm.value.more.employment_registration
    }
    if(type == 'graduation_cert'){
        uploadData.value.file = ruleForm.value.more.graduation_cert
    }
    if(type == 'handbook_commitment_letter'){
        uploadData.value.file = ruleForm.value.more.handbook_commitment_letter
    }
    if(type == 'resignation_report'){
        uploadData.value.file = ruleForm.value.more.resignation_report
    }
    if(type == 'out_report'){
        uploadData.value.file = ruleForm.value.more.out_report
    }
    if(type == 'handover_records'){
        uploadData.value.file = ruleForm.value.more.handover_records
    }
    if(type == 'salary_settlement_cert'){
        uploadData.value.file = ruleForm.value.more.salary_settlement_cert
    }
    if(type == 'resignation_cert'){
        uploadData.value.file = ruleForm.value.more.resignation_cert
    }
    if(type == 'resignation_interview_file'){
        uploadData.value.file = ruleForm.value.more.resignation_interview_file
    }
    
    uploadData.value.id = id.value
    showUpload.value = true
}

const saveUpload = (data:string) => {
    if(uploadData.value.type == 'avatar'){
        ruleForm.value.avatar = data
    }
    if(uploadData.value.type == 'salary_agreements'){
        ruleForm.value.more.salary_agreements = data
    }
    if(uploadData.value.type == 'social_security_cert'){
        ruleForm.value.more.social_security_cert = data
    }
    if(uploadData.value.type == 'bank_statement'){
        ruleForm.value.more.bank_statement = data
    }
    if(uploadData.value.type == 'employment_form'){
        ruleForm.value.more.employment_form = data
    }
    if(uploadData.value.type == 'labor_contract'){
        ruleForm.value.more.labor_contract = data
    }
    if(uploadData.value.type == 'company_policy_agreement'){
        ruleForm.value.more.company_policy_agreement = data
    }
    if(uploadData.value.type == 'probation_approval_form'){
        ruleForm.value.more.probation_approval_form = data
    }
    if(uploadData.value.type == 'idcard_file'){
        ruleForm.value.more.idcard_file = data
    }
    if(uploadData.value.type == 'contract'){
        ruleForm.value.more.contract = data
    }
    if(uploadData.value.type == 'employment_registration'){
        ruleForm.value.more.employment_registration = data
    }
    if(uploadData.value.type == 'graduation_cert'){
        ruleForm.value.more.graduation_cert = data
    }
    if(uploadData.value.type == 'handbook_commitment_letter'){
        ruleForm.value.more.handbook_commitment_letter = data
    }
    if(uploadData.value.type == 'resignation_report'){
        ruleForm.value.more.resignation_report = data
    }
    if(uploadData.value.type == 'out_report'){
        ruleForm.value.more.out_report = data
    }
    if(uploadData.value.type == 'handover_records'){
        ruleForm.value.more.handover_records = data
    }
    if(uploadData.value.type == 'salary_settlement_cert'){
        ruleForm.value.more.salary_settlement_cert = data
    }
    if(uploadData.value.type == 'resignation_cert'){
        ruleForm.value.more.resignation_cert = data
    }
    if(uploadData.value.type == 'resignation_interview_file'){
        ruleForm.value.more.resignation_interview_file = data
    }
    showUpload.value = false
}
</script>
<style scoped>
.el-tab-pane{height: calc(100vh - 25vh);overflow-y: scroll;}
::v-deep .el-form-item .el-form-item__label {
  font-size: 16px; /* 或者你想要的任何大小 */
}
::v-deep .el-tabs__item{font-size: 18px !important;}
</style>
